<?php
$screen = Blyn::app()->getCurrentNode()->getUIManager()->getCurrentScreen();
$notFindApplicationStr = Yii::t('site', 'not find application.');
$spaceUI = Blyn::app()->getActiveSpace()->getUIManager();
?>
<div>
    <div style="margin-top: 15px">
        <?php
        /** @var BootActiveForm $form */
        $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
            'id' => 'searchForm',
            'type' => 'search',
            'htmlOptions' => array('class' => 'well'),
        ));
        ?>
        <?php echo $form->textFieldRow($model, 'searchText', array('class' => 'input-medium', 'prepend' => '<i class="icon-search"></i>')); ?>        
        <?php
        //$ajaxSubmitBtn = $screen->buildAjaxLink('appStoreSearch', 'Search', NULL, NULL, NULL, array('class' => 'btn'));
        $searchStr = Yii::t('site', 'Search');
        $ajaxSubmitBtn = $screen->getAjaxLink($searchStr, array('htmlOptions' => array('class' => 'btn')));
        ?>
        <?php echo $ajaxSubmitBtn ?>
        <?php $this->endWidget(); ?>        
    </div>
</div>
<div class="well-small">
    <?php
//    $searchStr = Yii::t('site','Search');
    if ($screen->isAjaxLinkClicked($searchStr)) {
        ?>
        <?php $apps = $screen->getAppsData(); ?>
        <?php
        $add2SpaceStr = Yii::t('site', '+ Add to Space');
        $appNameStr = Yii::t('site', 'App Name:');
        if (count($apps) > 0) {
            echo '<table class="table table-hover">';
            foreach ($apps as $id => $name) {
                //$appLink =$screen->buildLink('addApp' . $id, '+ Add to Space', BUIScreen::LinkType_AjaxLink);
                $appLink = $screen->getAjaxLink($add2SpaceStr, array('ajaxLinkId' => 'addApp' . $id), NULL, NULL, $spaceUI);
                echo '<tr>';
                echo '<td><strong>' . $appNameStr . '</strong><span class="text-success" style="padding-left:10px"><strong> ' . Yii::t('site', $name) . '</strong></span></td>';
                echo '<td>' . $appLink . '</td>';
                echo '</tr>';
            }
            echo '</table>';
        } else {
            echo $notFindApplicationStr;
        }
        ?>
<?php } ?>
</div>